package com.cykj.eurekaribbon.service.impl;

import com.cykj.eurekaribbon.bean.FrontUser;
import com.cykj.eurekaribbon.service.FrontUserService;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

@Service
public class FrontUserServiceImpl implements FrontUserService {

    @Autowired
    RestTemplate restTemplate;


    /**
     * @version 1.0
     * @author: zhiMing
     * @date: 2021/9/28 01:00
     * @desc: 将乘客提交的code信息提交给后台
     * @param data
     * @return map
     */
    @Override
    public Map frontUserLogin(Map<String, String> data) {
        HttpHeaders httpHeaders = new HttpHeaders();
        MediaType type =  MediaType.parseMediaType("application/json; charset=UTF-8");
        httpHeaders.setContentType(type);
        httpHeaders.set("Connection", "Close");
        httpHeaders.add("Accept", MediaType.APPLICATION_JSON.toString());
        JSONObject jsonObj = JSONObject.fromObject(data);
        HttpEntity<String> formEntity = new HttpEntity<String>(jsonObj.toString(), httpHeaders);
        return restTemplate.postForObject("http://CLIENT/frontUserLogin",formEntity, Map.class);
    }

    /**
     * @version 1.0
     * @author: zhiMing
     * @date: 2021/10/07 03:00
     * @desc: 将乘客提交的头像以及客户信息提交至后台，进行头像更改
     * @param data
     * @return map
     */
    @Override
    public FrontUser getFrontUserAvatarUrl(Map<String, String> data) {
        HttpHeaders headers = new HttpHeaders();
        MediaType type =  MediaType.parseMediaType("application/json; charset=UTF-8");
        headers.setContentType(type);
        headers.set("Connection", "Close");
        headers.add("Accept", MediaType.APPLICATION_JSON.toString());
        JSONObject jsonObj = JSONObject.fromObject(data);
        HttpEntity<String> formEntity = new HttpEntity<String>(jsonObj.toString(), headers);
        return restTemplate.postForObject("http://CLIENT/updateFrontUserAvatar",formEntity, FrontUser.class);
    }
}
